window.onload=function(){
	$("#shuji").click(function(){
		switch_to_activity("shuji");
	});
	$("#settings").click(function(){
		switch_to_activity("settings");
	});
	$("#kebiao").click(function(){
		switch_to_activity("kebiao");
	});
	$("#daka").click(function(){
		switch_to_activity("daka");
	});
	$("#yikatong").click(function(){
		switch_to_activity("yikatong");
	});
	$("#fuwu").click(function(){
		switch_to_activity("fuwu");
	});
	$("#xxmh").click(function(){
		switch_to_activity("xxmh");
	});
	$("#jwxt").click(function(){
		switch_to_activity("jwxt");
	});

    showHello();
	window.setInterval(showHitokoto,9000);
	window.JSBridge.setHtml_title();
}
function java_savedata(data){
    alert("java call")
}
function switch_to_activity(flag_str0){
	window.JSBridge.switch_to_page(flag_str0);
}
function toast_sth(flag_str1){
		window.JSBridge.toaststh(flag_str1);

}
function gettitle(){
		window.JSBridge.setHtml_title();
}

function settitle(str1){
	var d = new Date();
	var nowtime=Number( d.getHours() );
	if( nowtime<=4 || nowtime>=19){
		str0="晚上好，"
	}else if(nowtime>4 && nowtime<11){
		str0="早上好，"
	}else if(nowtime>=11 && nowtime<=14){
		str0="中午好，"
	}else if(nowtime>14 && nowtime<19){
	    str0="下午好，"
     }else{
        str0="你好，"
     }
	var str2=str0+str1;
	var name=document.getElementById("name")
	name.innerText=str2;
}
function alertsth(str1){
    swal(str1);
}

function showHitokoto(){
    $.getJSON('https://v1.hitokoto.cn/?c=d&c=e&c=f&c=i&c=j&c=k&c=l',function(result){
        showMessage('「 '+result.hitokoto+' 」'+'<br>'+"—— "+result.from, 7000);
    });
}
function showMessage(text, timeout){
    if(Array.isArray(text)) text = text[Math.floor(Math.random() * text.length + 1)-1];
    //console.log('showMessage', text);
    $('.message').stop();
    $('.message').html(text).fadeTo(200, 0.3);
    $('.message').html(text).fadeTo(200, 0.6)
    $('.message').html(text).fadeTo(200, 0.8);
    $('.message').html(text).fadeTo(200, 1);
    if (timeout === null) timeout = 5000;
    hideMessage(timeout);
}
function showHello(){
    var now = (new Date()).getHours();
    //var date = new Date();
    //var now = 6;
    if (now > 23 || now <= 5) {
        text = '你是夜猫子呀？这么晚还不睡觉，明天起的来嘛？';
        showMessage(text, 6000);
    } else if (now > 5 && now <= 7) {
        text = '早上好！一日之计在于晨，美好的一天就要开始了！';
        showMessage(text, 6000);
    } else if (now > 7 && now <= 11) {
        text = '上午好！工作顺利嘛，不要久坐，多起来走动走动哦！';
        showMessage(text, 6000);
    } else if (now > 11 && now <= 13) {
        text = '中午了，工作了一个上午，现在是午餐时间！';
        showMessage(text, 6000);
    } else if (now > 13 && now <= 17) {
        text = '午后很容易犯困呢，今天的运动目标完成了吗？';
        showMessage(text, 6000);
    } else if (now > 17 && now <= 19) {
        text = '傍晚了！窗外夕阳的景色很美丽呢，最美不过夕阳红~~';
        showMessage(text, 6000);
    } else if (now > 19 && now <= 21) {
    text = '晚上好，今天过得怎么样？';
        showMessage(text, 6000);
    } else if (now > 21 && now <= 23) {
        text = '已经这么晚了呀，早点休息吧，晚安~~';
        showMessage(text, 6000);
    } else {
        showHitokoto();
    }
}
function hideMessage(timeout){
    $('.message').stop().css('opacity',1);
    if (timeout === null) timeout = 5000;
    $('.message').delay(timeout).fadeTo(500, 0);
}


function rwLS(str,key,value){
	if(str == 'r'){
		return localStorage.getItem(key);
	}else if(str == 'w'){
		localStorage.setItem(key,value);
		return 1;
	}else if(str == 'rm'){
		localStorage.removeItem(key);
		return 2;
	}
}

